<template>
  <div>
    <artificial-perform @cancle="cancle" :initData="updateData" @save="updateForm" :cycleOptions="cycleOptions" :title="title">
    </artificial-perform>
  </div>
</template>

<script>
  import ArtificialPerform from '../../base/artificial-perform/Form'
  export default {
    name: 'UpdateArtificialPerformance',
    data () {
      return {
        title: this.$t('public.edit'),
        updateData: {}
      }
    },
    props: {
      initData: Object,
      cycleOptions: {
        type: Array,
        default: function () {
          return []
        }
      }
    },
    watch: {
      initData () {
        this.changeValue()
      }
    },
    methods: {
      changeValue () {
        this.updateData = JSON.parse(JSON.stringify(this.initData))
        let check = true
        this.cycleOptions.map(item => {
          if (item.value === this.updateData.cycle) {
            check = false
          }
        })
        if (check && this.cycleOptions.length > 0) {
          this.updateData.cycle = this.cycleOptions[0].value
        }
      },
      updateForm (form) {
        this.$emit('update', form)
      },
      cancle () {
        this.$emit('cancle')
      }
    },
    components: {
      ArtificialPerform
    },
    beforeMount () {
      this.changeValue()
    }
  }
</script>
